package com.topwalk.datacollect.dao.imp;

import com.topwalk.datacollect.dao.BizLinkTaskDao;
import com.topwalk.datacollect.model.BizLinkTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

@Repository
public class BizLinkTaskDaoImpl implements BizLinkTaskDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    class BizLinkTaskRowMapper implements RowMapper<BizLinkTask>{
        @Override
        public BizLinkTask mapRow(ResultSet resultSet, int i) throws SQLException {
            BizLinkTask bizLinkTask = new BizLinkTask();
            bizLinkTask.setId(resultSet.getInt("id"));
            bizLinkTask.setTaskID(resultSet.getString("taskID"));
            bizLinkTask.setBizID(resultSet.getString("bizID"));
//            bizLinkTask.setTbdtplinkinfid(resultSet.getString("dtpLinkInfo"));
            return bizLinkTask;
        }
    }






    @Override
    public BizLinkTask findByTaskID(String taskID) {
        String sql = "select * from t_zc_biz_task where taskID = ?";
        BizLinkTask bizLinkTask;
        try {
            bizLinkTask = jdbcTemplate.queryForObject(sql, new BizLinkTaskRowMapper(), taskID);
        }catch (EmptyResultDataAccessException e){
            return null;
        }
        return bizLinkTask;
    }
}
